var getGaojing = (arr,num) =>{
    let res = {};
    if(!(arr instanceof Array) || arr.length <= 1){
        return {code:0,msg:"节点太少，无法计算",data:""};
    }
    var sum = 0;
    var pre = 0;
    var distance = num * 200 / 1.9;
    for(var i=0;i<arr.length;i++){
        pre = sum;
        if(i == arr.length - 1){
            res.code = 0;
            res.msg = "故障点超出坐标点范围";
            res.data = ""
            return res;
        }else{
            let x1 = 3836187.737 * (0 + arr[i]['longitude'] - 109.88595);
            let y1 = -7091297.591 * (0 + arr[i]['latitude'] - 40.65176);
            let x2 = 3836187.737 * (0 + list[i + 1]['longitude'] - 109.88595);
            let y2 = -7091297.591 * (0 + list[i + 1]['latitude'] - 40.65176);
            let Len = Math.abs(Math.sqrt(Math.pow(x2 - x1,2) + Math.pow(y2 - y1,2)));
            sum = sum + Len;
            if(distance <= sum){
                res.code = 1;
                res.msg = "ok";
                res.data.type = 2;
                res.data.origin = arr[i]['nodeName'];
                res.data.finishing = arr[i + 1]['nodeName'];
                res.data.originId = arr[i]['opticalId'];
                res.data.finishingId = arr[i + 1]['opticalId'];
                let len = distance - pre;
                let n = len / Len;
                let x = x1 + n * (x2 - x1);
                let y = y1 + n * (y2 - y1);
                res.data.x = x;
                res.data.y = y;
                res.data.distance = Math.floor(len * 1.9 / 100);
                return res;
            }
        }
    }
}

module.exports = {getGaojing};